package com.asen.commons.core.base.result;

import com.asen.commons.core.base.enums.ResultTypeEnum;
import com.asen.commons.core.base.ResultCode;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public class BaseResultCode implements ResultCode {
    public static final ResultCode C0000;
    public static final ResultCode W0000;
    public static final ResultCode E0000;
    public static final ResultCode E0002;
    public static final ResultCode E0003;
    public static final ResultCode E0004;
    public static final ResultCode E0005;
    public static final ResultCode E0006;
    public static final ResultCode E0007;
    public static final ResultCode E0008;
    public static final ResultCode E0101;
    public static final ResultCode E0102;
    public static final ResultCode E0103;
    public static final ResultCode E0104;
    public static final ResultCode E2000;
    public static final ResultCode E2001;
    private ResultTypeEnum type;
    private String code;
    private String message;

    public BaseResultCode() {
        this.type = ResultTypeEnum.ERROR;
    }

    public BaseResultCode(String code) {
        this.type = ResultTypeEnum.ERROR;
        this.code = code;
    }

    public BaseResultCode(String code, String message) {
        this.type = ResultTypeEnum.ERROR;
        this.code = code;
        this.message = message;
    }

    public BaseResultCode(ResultTypeEnum type, String code) {
        this.type = type;
        this.code = code;
    }

    public BaseResultCode(ResultTypeEnum type, String code, String message) {
        this.type = type;
        this.code = code;
        this.message = message;
    }

    public static ResultCode of(String code) {
        return new BaseResultCode(code);
    }

    public static ResultCode of(String code, String message) {
        return new BaseResultCode(code, message);
    }

    public static ResultCode of(ResultTypeEnum type, String code) {
        return new BaseResultCode(type, code);
    }

    public static ResultCode of(ResultTypeEnum type, String code, String message) {
        return new BaseResultCode(type, code, message);
    }

    public String getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public ResultTypeEnum getType() {
        return this.type;
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o != null && this.getClass() == o.getClass()) {
            BaseResultCode that = (BaseResultCode)o;
            return (new EqualsBuilder()).append(this.getType(), that.type).append(this.getCode(), that.code).append(this.getMessage(), that.message).isEquals();
        } else {
            return false;
        }
    }

    public int hashCode() {
        return (new HashCodeBuilder(17, 37)).append(this.getType()).append(this.getCode()).append(this.getMessage()).toHashCode();
    }

    public String toString() {
        return "BaseResultCode{type=" + this.getType() + ", code='" + this.getCode() + '\'' + ", message='" + this.getMessage() + '\'' + '}';
    }

    static {
        C0000 = new BaseResultCode(ResultTypeEnum.INFO, "C0000", "处理成功");
        W0000 = new BaseResultCode(ResultTypeEnum.WARN, "W0000", "请确认");
        E0000 = new BaseResultCode(ResultTypeEnum.ERROR, "E0000", "服务器正忙，请稍后");
        E0002 = new BaseResultCode(ResultTypeEnum.ERROR, "E0002", "参数不全或无效");
        E0003 = new BaseResultCode(ResultTypeEnum.ERROR, "E0003", "用户未登录");
        E0004 = new BaseResultCode(ResultTypeEnum.ERROR, "E0004", "记录已存在");
        E0005 = new BaseResultCode(ResultTypeEnum.ERROR, "E0005", "权限不足,请联系管理员");
        E0006 = new BaseResultCode(ResultTypeEnum.ERROR, "E0006", "当前不是最新数据，请获取最新数据后重试");
        E0007 = new BaseResultCode(ResultTypeEnum.ERROR, "E0007", "数据不存在或已删除");
        E0008 = new BaseResultCode(ResultTypeEnum.ERROR, "E0008", "接口不存在");
        E0101 = new BaseResultCode(ResultTypeEnum.ERROR, "E0101", "登录不合法");
        E0102 = new BaseResultCode(ResultTypeEnum.ERROR, "E0102", "重复登录");
        E0103 = new BaseResultCode(ResultTypeEnum.ERROR, "E0103", "登录已过期");
        E0104 = new BaseResultCode(ResultTypeEnum.ERROR, "E0104", "登录已过期");
        E2000 = of("E2000", "接口异常，连接超时");
        E2001 = of("E2001", "接口异常，读取数据超时");
    }
}
